package com.gnerv.rabbitmq.agent.common.model;

/**
 * <p>
 * 通用返回状态码
 * </p>
 *
 * @author Gnerv LiGen
 * @since 2019-09-24
 */
public enum ResultCode {

    /**
     * 请求成功
     */
    CODE_200(200, "请求成功"),

    CODE_400(400, "参数异常"),
    CODE_401(401, "权限异常"),
    CODE_402(402, "未登陆或者登陆失效"),
    CODE_403(403, "禁止访问"),
    CODE_404(404, "资源不存在"),
    CODE_405(405, "登录失败"),

    CODE_500(500, "系统异常"),
    CODE_503(503, "数据库异常");

    private final Integer key;
    private final String desc;

    ResultCode(Integer key, String desc) {
        this.key = key;
        this.desc = desc;
    }

    public static ResultCode getType(Integer key) {
        for (ResultCode type : values()) {
            if (type.key.equals(key)) {
                return type;
            }
        }
        return null;
    }

    public Integer getKey() {
        return key;
    }

    public String getDesc() {
        return desc;
    }

}
